#include "form_mjs.h"

FormMjs::FormMjs()
{
}
FormMjs::~FormMjs()
{
}

int FormMjs::add_form(ZU_TYPE form_type, Mj mj, int from_seat)
{
	if (form_type == PENG)
	{
		MJZ mjz;
		mjz.zu_type = PENG;
		mjz.from_seat = from_seat;
		for (int i=0; i<3; i++)
		{
			mjz.zu_mjs.push_back(mj);
		}
		form_mjz.push_back(mjz);
	}
	else if (form_type == FANG_GANG)
	{
		MJZ mjz;
		mjz.zu_type = FANG_GANG;
		mjz.from_seat = from_seat;
		for (int i=0; i<4; i++)
		{
			mjz.zu_mjs.push_back(mj);
		}		
		form_mjz.push_back(mjz);
	}
	else if (form_type == ANG_GANG)
	{
		MJZ mjz;
		mjz.zu_type = ANG_GANG;		
		mjz.from_seat = from_seat;
		for (int i=0; i<4; i++)
		{
			mjz.zu_mjs.push_back(mj);
		}
		form_mjz.push_back(mjz);
	}
	else if (form_type == MING_GANG)
	{
		for (unsigned int i=0; i<form_mjz.size(); i++)
		{
			MJZ &mjz = form_mjz[i];
			if (mjz.zu_type != PENG) continue;
			if (mjz.zu_mjs[0].val == mj.val)
			{
				mjz.zu_type = MING_GANG;
				mjz.zu_mjs.push_back(mj);
				return 0;
			}
		}
	}
	
	return 0;
}

bool FormMjs::check_same_ke_mj(Mj mj)
{
	for (unsigned int i=0; i<form_mjz.size(); i++)
	{
		MJZ mjz = form_mjz[i];
	    if (mjz.zu_type == PENG && mjz.zu_mjs[0].val == mj.val)
	    {
	    	return true;
	    }
	}
	return false;
}

int FormMjs::get_one_mj_num(Mj ji_mj)
{
	int cnt = 0;
	for (unsigned int i=0; i<form_mjz.size(); i++) 
	{
			MJZ mjz = form_mjz[i];
			for (unsigned int j=0; j<mjz.zu_mjs.size(); j++)
			{
				Mj mj = mjz.zu_mjs[j];
				if (mj.val == ji_mj.val)
				{
					cnt++;
				}
			}
	}
	return cnt;
}





